package com.example.riseofthedefender;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.PointF;

public class ParallaxBackground{
	
	public static float wHlv, hHlv;
	public static PointF pos = new PointF();
	
	public static void init(){
		wHlv = GameVar.cWidthH;
		hHlv = GameVar.cHeightH;
	}
	
	public static void update()
	{
		pos.x-=Camera.velocity.x*0.2f;
		if(pos.x>GameVar.cWidth)
			pos.x-=GameVar.cWidth;
		else if(pos.x<0)
			pos.x+=GameVar.cWidth;
		pos.y-=Camera.velocity.y*0.2f;
		if(pos.y>GameVar.cWidth)
			pos.y-=GameVar.cWidth;
		else if(pos.y<0)
			pos.y+=GameVar.cWidth;
			
	}
	
	public static void draw(GL10 gl) {
		
		if(pos.x < GameVar.cWidth && pos.y < GameVar.cHeight)
		{
			gl.glLoadIdentity();
			gl.glTranslatef(pos.x+wHlv, pos.y+wHlv, 0.0f);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
			gl.glScalef(wHlv, wHlv, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
		}
		if(pos.x < GameVar.cWidth && pos.y > 0)
		{
			gl.glLoadIdentity();
			gl.glTranslatef(pos.x+wHlv, pos.y-wHlv, 0.0f);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
			gl.glScalef(wHlv, wHlv, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
		}
		if(pos.x > 0 && pos.y < GameVar.cHeight)
		{
			gl.glLoadIdentity();
			gl.glTranslatef(pos.x-wHlv, pos.y+wHlv, 0.0f);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
			gl.glScalef(wHlv, wHlv, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
		}
		if(pos.x > 0 && pos.y > 0)
		{
			gl.glLoadIdentity();
			gl.glTranslatef(pos.x-wHlv, pos.y-wHlv, 0.0f);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
			gl.glScalef(wHlv, wHlv, 1.0f);
			gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
		}
		
		
//		gl.glLoadIdentity();
//		//gl.glTranslatef(-Camera.pos.x,-Camera.pos.y,0.0f);
//		gl.glTranslatef(pos.x+wHlv, pos.y+hHlv, 0.0f);
//		gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
//		gl.glScalef(wHlv, wHlv, 1.0f);
//		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
//		
//		gl.glLoadIdentity();
//		//gl.glTranslatef(-Camera.pos.x,-Camera.pos.y,0.0f);
//		gl.glTranslatef(pos.x-wHlv, pos.y+hHlv, 0.0f);
//		gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.TEXTURE1.textures[0]);
//		gl.glScalef(wHlv, wHlv, 1.0f);
//		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
//		
		
	}
}
